namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    public class IndicatorPBX : BaseIndicator
    {
        private string pbxEmaField = ("PBX.PbxEmaField" + Common.GetGuid());
        private string pbxLongMaField = ("PBX.PbxLongMaField" + Common.GetGuid());
        private string pbxShortMaField = ("PBX.PbxShortMaField" + Common.GetGuid());
        private LineShape tlsPbx;

        public IndicatorPBX()
        {
            base.IndType = IndicatorType.PBX;
            base.IndName = "PBX";
            base.IndDesc = "瀑布线";
            base.IndPeriod.Add(new IndicatorPeriod(0, "N", 4.0));
            base.SourceDic["Close"] = "";
            base.fields = new string[] { "PBX" };
        }

        public override bool Contains(object obj)
        {
            return (obj == this.tlsPbx);
        }

        public override double[] Get(int r)
        {
            double curValue = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Close"]]);
            double num2 = Common.CalculateExponentialMovingAvg(this.pbxEmaField, base.SourceDic["Close"], (int) base.IndPeriod[0].ParamValue, curValue, base.Crab.DataSource, r);
            double num3 = Common.CalcuteMovingAvg(r, ((int) base.IndPeriod[0].ParamValue) * 2, this.pbxShortMaField, base.SourceDic["Close"], curValue, base.Crab.DataSource);
            double num4 = Common.CalcuteMovingAvg(r, ((int) base.IndPeriod[0].ParamValue) * 4, this.pbxLongMaField, base.SourceDic["Close"], curValue, base.Crab.DataSource);
            double num5 = ((num2 + num3) + num4) / 3.0;
            return new double[] { num2, num3, num4, num5 };
        }

        public override List<BaseShape> GetShapeList()
        {
            return new List<BaseShape> { this.tlsPbx };
        }

        public override void Remove()
        {
            base.Crab.DeleteShape(this.TlsPbx);
            base.Crab.DataSource.Columns.Remove(this.PbxEmaField);
            base.Crab.DataSource.Columns.Remove(this.PbxLongMaField);
            base.Crab.DataSource.Columns.Remove(this.PbxShortMaField);
        }

        public override bool Set(int r, string target)
        {
            try
            {
                DataRow row = base.Crab.DataSource.Rows[r];
                foreach (string str in base.SourceDic.Values)
                {
                    if ((str == target) || (target == null))
                    {
                        foreach (string str2 in base.SourceDic.Values)
                        {
                            if (row[str2] is DBNull)
                            {
                                return false;
                            }
                        }
                        double[] numArray = this.Get(r);
                        base.Crab.SetValue(this.PbxEmaField, numArray[0], r);
                        base.Crab.SetValue(this.PbxShortMaField, numArray[1], r);
                        base.Crab.SetValue(this.PbxLongMaField, numArray[2], r);
                        base.Crab.SetValue(this.TlsPbx.Name, numArray[3], r);
                        return true;
                    }
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        public override void SetParam(string[] fields, string[] source, double[] periods, int panelID)
        {
            this.TlsPbx = base.Crab.AddLine(fields[0], panelID);
            base.Crab.SetLine(fields[0], fields[0], Color.White, 1, 0.01, 2, DashStyle.Solid);
            base.IndPeriod[0].ParamValue = periods[0];
            base.Crab.DataSource.Columns.Add(this.PbxEmaField);
            base.Crab.DataSource.Columns.Add(this.PbxShortMaField);
            base.Crab.DataSource.Columns.Add(this.PbxLongMaField);
            base.SourceDic["Close"] = source[0];
        }

        public string PbxEmaField
        {
            get
            {
                return this.pbxEmaField;
            }
            set
            {
                this.pbxEmaField = value;
            }
        }

        public string PbxLongMaField
        {
            get
            {
                return this.pbxLongMaField;
            }
            set
            {
                this.pbxLongMaField = value;
            }
        }

        public string PbxShortMaField
        {
            get
            {
                return this.pbxShortMaField;
            }
            set
            {
                this.pbxShortMaField = value;
            }
        }

        public LineShape TlsPbx
        {
            get
            {
                return this.tlsPbx;
            }
            set
            {
                this.tlsPbx = value;
            }
        }
    }
}

